<?php

/**
 * 
 * @author szm
 */
class Expansion_model  extends CI_Model{
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }
    
    public function getAllItems($lessonIds){
        	try{
		        if(empty($lessonIds)){
		            return array();
	        }
	        if(!is_array($lessonIds)){
	            $lessonIds=array($lessonIds);
	        }
	        $lessonIds=implode(",",$lessonIds);
	        $this->db->select('*');
	        $this->db->from('expansion as es');
	        $this->db->join('sentence  as ss','es.sentence_id=ss.sentence_id' ,'inner');
	        $this->db->join('sentence_source_1 as sc', 'sc.sentence_id  = ss.sentence_id ', 'left');
	        $this->db->join('zh_jp_dictionary as dic','es.sentence_id=dic.sentence_id','left');
	        $this->db->where_in('ss.lesson_id',$lessonIds);
	        $result=$this->db->get();
	        $rs=$result->result_array();
	        return $rs;

	     }catch(Exception $e){
            return array();
         }
    }
    /**
     * deleted
     * @param unknown_type $lessonIds
     */
    public function getExpansions($lessonIds){
        if(empty($lessonIds)){
            return false;
        }
        if(!is_array($lessonIds)){
            $lessonIds=array($lessonIds);
        }
        $lessonIds=implode(",",$lessonIds);
        $sql="select g.* from expansion_sentences as es
			left join sample_sentences  as ss on es.sample_sentence_id  = ss.sample_sentence_id 
			left join glossary as g on g.glossary_id=es.glossary_id
			where ss.lesson_id in ($lessonIds)";
        
	     try{
            $dbSource=$this->db->query($sql);
            $resultArr=$dbSource->result_array();
            return $resultArr;
	     }catch(Exception $e){
            return $sql;
         }
    }
    public function listAllExpansions(){

    }
    
    public function getExpansion(){

    }
    
    public function saveExpansion(){


    }
    
    public function removeExpansion(){

    }

}

